package com.pioneer.cloudstorage.utils;

import java.util.Optional;

public class FileUtils {

    public static String getFileExtension(String filename) {
        return Optional.ofNullable(filename)
                .filter(f -> f.contains("."))
                .map(f -> f.substring(filename.lastIndexOf(".") + 1))
                .orElse("");
    }

    public static String getFileNameWithoutExtension(String filename) {
        if (filename == null) return "";
        int dotIndex = filename.lastIndexOf(".");
        return (dotIndex == -1) ? filename : filename.substring(0, dotIndex);
    }
}